package com.example.design.obServerDemo;

import java.util.ArrayList;
import java.util.List;

public class Subject {

  private List<Observer> observerList = new ArrayList<Observer>();

  private String name;


  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
    notifyAllObservers();
  }

  public void notifyAllObservers() {
    for (Observer observer : observerList) {
      observer.service();
    }
  }

  public void addObserver(Observer observer) {
    this.observerList.add(observer);
  }
}
